/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 2

Using: Hw1Types.h

Description:
TestManager keeps all the tests and runs them when requested. It had a 
linked list to hold all tests. It has some enums used for functions 
results, but the main data type is TTestDetails, which is held in the 
linked list (for each test), and holds important info on each test.
oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#ifndef TEST_MANAGER_H
#define TEST_MANAGER_H


#include <tchar.h>
#include <windows.h>


/**
 * This enum states the result of a test ran by TestManager
 * TEST_RESULT_SUCCESS - Test was completed successfully
 * TEST_RESULT_FAILURE - Test was completed and return negative results
 * TEST_RESULT_TIMEOUT - Test was not completed - The tested process did not end in time
 * TEST_RESULT_COLLAPSED - Test was not completed - The tested process returned a different exit code than expected
 * TEST_FAILED - There was a problem running the test
 */ 
typedef enum { TEST_RESULT_SUCCESS, TEST_RESULT_FAILURE, TEST_RESULT_TIMEOUT, TEST_RESULT_COLLAPSED, TEST_FAILED } ETestResult;
#define MAX_RESULT_STRING 25

typedef enum { THREAD_TEST_COMPLETED_SUCCESSFULLY = 0, THREAD_TEST_ERROR = -1, THREAD_ERROR = -2};

typedef struct 
{
    int TestNumber;
	char* ExeFilename;
	char* Arguments;
	char* ExeOutputFile;
	char* ReferenceOutputFile;
	int Timeout;
	int TestStartTime;
	int TestEndTime;
	DWORD ThreadID;
    HANDLE ThreadHandle;
	ETestResult TestResult;
} TTestDetails;
typedef TTestDetails* PTestDetails;

/* InitializeTestManager(int a_iSuccessStatusCode)
 * ------------------------------------------------
 * Initializes the test manager with the status code that states success                                                                                     */
BOOL InitializeTestManager(int a_iSuccessStatusCode);

/* FreeTestManager()
 * -----------------
 * Frees everything. As expected                            */
void FreeTestManager();

/* AddTest(int testNumber, const char* exeFilename, const char* arguments, const int timeoutMs, const int successExitCode, const char* outputFilename, const char* referenceOutputFilename);
 * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 * Adds a test to the list                                                      */
BOOL AddTest(int testNumber, const char* exeFilename, const char* arguments, const int timeoutMs, const int successExitCode, const char* outputFilename, const char* referenceOutputFilename);

/* LoadTests(TCHAR* filename, TCHAR* aExeFilename)
 * ------------------------------------------------
 * Loads a test list from a file, and sets the tested exe filename              */
BOOL LoadTests(TCHAR* filename, TCHAR* aExeFilename);

/* RunTests()
 * ----------
 * Runs the tests (parallely) loaded in LoadTests           */
BOOL RunTests();

/* ReportResult()
 * --------------
 * Report the results of the testing process to a file      */
BOOL ReportResult(TCHAR* correctnessFilename, TCHAR* runtimeFilename);

#endif // TEST_MANAGER_H